package com.cspg.ssss.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cspg.ssss.service.WordExService;
import com.cspg.ssss.util.WordExUtil;
import com.cspg.ssss.vo.ProblemConfig;
import com.cspg.ssss.vo.ResultVo;
import com.cspg.ssss.vo.ResultVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/wordex")
public class WordEXController {
    @Autowired
    private WordExService wordExService;
    @Autowired
    private ProblemConfig config;

    @RequestMapping(value = "/selectst", method = RequestMethod.POST)
    public ResultVo selectst(@RequestParam("creattime") String creattime, @RequestParam("endtime") String endtime) {
        ResultVo retVo = null;
        try {
            Calendar calendar = Calendar.getInstance();
            /* String dwmc="广州局";*/
            if ("".equals(creattime) || "".equals(endtime)) {
                int year = calendar.get(Calendar.YEAR);
                String years = String.valueOf(year);
                creattime = years + "-01-01";
                endtime = years + "-12-31";
            }

            /* 公司模板*/
            List<Map> list1 = wordExService.selectst1(creattime, endtime);//查询问题发现方式分类汇总
            List<Map> list2 = wordExService.selectst2(creattime, endtime);//查询问题部门分布情况
            List<Map> list3 = wordExService.selectst3(creattime, endtime);//查询问题专业类别分布情况
            List<Map> list4 = wordExService.selectst4(creattime, endtime);//查询问题业务事项分布情况
            List<Map> list5 = wordExService.selectst5(creattime, endtime);//查询问题所属层面分布情况
            List<Map> list6 = wordExService.selectst6(creattime, endtime);//查询问题管理环节分布情况
            List<Map> list7 = wordExService.selectst7(creattime, endtime);//查询问题类别分布情况
            List<Map> list8 = wordExService.selectst8(creattime, endtime);//查询问题对应体系单元分布情况
            List<Map> list9 = wordExService.selectst9(creattime, endtime);//查询问题对应体系要素分布情况
            List<Map> list10 = wordExService.selectst10(creattime, endtime);//查询问题严重程度分布情况
            List<Map> list11 = wordExService.selectst11(creattime, endtime);//查询三老问题分布情况
            List<Map> list12 = wordExService.selectst12(creattime, endtime);//查询三老问题单位分布情况
            List<Map> list13 = wordExService.selectst13(creattime, endtime);//查询是否主动暴露分布情况
            List<Map> list14 = wordExService.selectst14(creattime, endtime);//查询是否主动暴露单位分布情况
            List<Map> list15 = wordExService.selectst15(creattime, endtime);//查询问题整改情况
            List<Map> list16 = wordExService.selectst16(creattime, endtime);//查询问题整改情况

            int a = wordExService.selectall(creattime, endtime);//查询问题总数
            int u = wordExService.selectzys(creattime, endtime);//总验收
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("creattime", creattime);
            map.put("endtime", endtime);
            String d = "";
            DecimalFormat df = new DecimalFormat("0.00");//格式化小数
            String zwcl = df.format((double) u / a * 100);
            map.put("wtzs", a);
            map.put("zwcl", zwcl);
            /* 问题发现方式开始+++++++++++++++++++++++++++++++++++++++++*/
            //问题发现方式占比
            if (list1.size() > 0) {
                for (int i = 0; i < list1.size(); i++) {
                    d = list1.get(i).get("sl").toString(); //获取每一项的数量
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list1.get(i).put("num", num);
                }
            }
            // 2021-6-28 ybq改：添加自定义
            Map<String, Object> othen = new HashMap<>();
            othen.put("wtfxfs", "其他");
            int wtfxfs_sl = 0;
            double wtfxfs_num = 0;
            List<Map> wtfxfslb = new ArrayList<>();
            for (Map data : list1) {
                if (config.getFoundWay().contains(data.get("wtfxfs"))) {
                    wtfxfslb.add(data);
                } else {
                    wtfxfs_sl += Integer.parseInt(data.get("sl").toString());
                    wtfxfs_num += Double.parseDouble(data.get("num").toString());
                }
            }
            if (wtfxfs_sl > 0) {
                othen.put("sl", wtfxfs_sl);
                othen.put("num", wtfxfs_num + "");
                wtfxfslb.add(othen);
                wtfxfslb.sort((u1, u2) -> {
                    int diff = Integer.parseInt(u1.get("sl").toString()) - Integer.parseInt(u2.get("sl").toString());
                    if (diff > 0) {
                        return 1;
                    } else if (diff < 0) {
                        return -1;
                    }
                    return 0; //相等为0
                });
            }
            map.put("wtfxfslb", wtfxfslb); //将问题发现方式列表存放
            /* 问题发现方式结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    d = list2.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list2.get(i).put("num", num);
                }
            }
            map.put("wtdwfblb", list2);
            /* 问题单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题专业类别开始+++++++++++++++++++++++++++++++++++++++++*/
            //问题发现方式占比
            List<String> wtzylb = new ArrayList<>();
            List<String> typeList = config.getProfessionalType();
            if (list3.size() > 0) {
                for (int i = 0; i < list3.size(); i++) {
                    d = list3.get(i).get("sl").toString(); //获取每一项的数量
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list3.get(i).put("num", num);
                    if (typeList.contains(list3.get(i).get("zylb"))) {
                        wtzylb.add(list3.get(i).get("zylb").toString());
                    }
                }
            }
            for (String type : typeList) {
                if (!wtzylb.contains(type)) {
                    Map data = new HashMap();
                    data.put("zylb", type);
                    data.put("sl", 0);
                    data.put("num", "0");
                    list3.add(data);
                }
            }
            map.put("wtzylb", list3);
            /* 问题专业类别结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题业务事项分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list4.size() > 0) {
                for (int i = 0; i < list4.size(); i++) {
                    d = list4.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list4.get(i).put("num", num);
                }
            }
            map.put("wtywsxlb", list4);
            /* 问题业务事项分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题所属层面分布开始+++++++++++++++++++++++++++++++++++++++++*/
            List<String> levelList = config.getLevel();
            if (list5.size() > 0) {
                for (int i = 0; i < list5.size(); i++) {
                    d = list5.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list5.get(i).put("num", num);
                }
            }
            List<Map> wtsscmlb = new ArrayList<>();
            for (String level : levelList) {
                boolean wtsscmlbCon = true;
                for (Map value : list5) {
                    if (value.get("sscm").equals(level)) {
                        wtsscmlb.add(value);
                        wtsscmlbCon = false;
                        break;
                    }
                }
                if (wtsscmlbCon) {
                    Map data = new HashMap();
                    data.put("sscm", level);
                    data.put("sl", 0);
                    data.put("num", "0");
                    wtsscmlb.add(data);
                }
            }
            map.put("wtsscmlb", wtsscmlb);
            /* 问题所属层面分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题管理环节分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list6.size() > 0) {
                for (int i = 0; i < list6.size(); i++) {
                    d = list6.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list6.get(i).put("num", num);
                }
            }
            map.put("wtglhjlb", list6);
            /* 问题管理环节分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题类别分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list7.size() > 0) {
                for (int i = 0; i < list7.size(); i++) {
                    d = list7.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list7.get(i).put("num", num);
                }
            }
            map.put("wtlblb", list7);
            /* 问题类别分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题对应体系单元开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list8.size() > 0) {
                for (int i = 0; i < list8.size(); i++) {
                    d = list8.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list8.get(i).put("num", num);
                }
            }
            map.put("wtdytxdylb", list8);
            /* 问题对应体系单元结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题对应体系要素开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list9.size() > 0) {
                for (int i = 0; i < list9.size(); i++) {
                    d = list9.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list9.get(i).put("num", num);
                }
            }
            map.put("wtdytxyslb", list9);
            /* 问题对应体系要素结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题严重程度开始+++++++++++++++++++++++++++++++++++++++++*/
            List<String> severityList = config.getSeverity();
            if (list10.size() > 0) {
                for (int i = 0; i < list10.size(); i++) {
                    d = list10.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list10.get(i).put("num", num);
                }
            }
            List<Map> wtyzcdlb = new ArrayList<>();
            for (String severity : severityList) {
                boolean wtyzcdlbCon = true;
                for (Map value : list10) {
                    if (value.get("wtyzcd").equals(severity)) {
                        wtyzcdlb.add(value);
                        wtyzcdlbCon = false;
                        break;
                    }
                }
                if (wtyzcdlbCon) {
                    Map data = new HashMap();
                    data.put("wtyzcd", severity);
                    data.put("sl", 0);
                    data.put("num", "0");
                    wtyzcdlb.add(data);
                }
            }
            map.put("wtyzcdlb", wtyzcdlb);
            /* 问题严重成结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否三老问题总开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfslwt1", list11);
            /* 是否三老问题总结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否三老问题单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfslwt2", list12);
            /* 是否三老问题单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否主动暴露总开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfzdbl1", list13);
            /* 是否主动暴露总结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否主动暴露单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfzdbl2", list14);
            /* 是否主动暴露单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 整改问题情况开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list15.size() > 0) {
                for (int i = 0; i < list15.size(); i++) {
                    d = list15.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list15.get(i).put("num", num);
                }
            }
            map.put("wtzgz", list15);
            /* 整改问题情况结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 单位整改问题情况开始+++++++++++++++++++++++++++++++++++++++++*/
            List<Map> departmentList = wordExService.selectDepartment();
            List result = new ArrayList();
            for (Map depart : departmentList) {
                List datas = findAlllInData(depart, list16); //在datalist里面找与depart相同的记录，返回一个数组
                Map dataMap = new HashMap();
                dataMap.put(depart.get("department_name"), datas);
                result.add(dataMap);
            }
            map.put("wtzgdw", result);
            /* 单位整改问题情况结束+++++++++++++++++++++++++++++++++++++++++*/
            List result2 = new ArrayList();
            List<Map> selectdwwtzsall = wordExService.selectdwwtzsall(creattime, endtime);  //各单位问题总数
            List<Map> selectdwysall = wordExService.selectdwysall(creattime, endtime);//各单位已验收问题总数
            for (int i = 0; i < selectdwwtzsall.size(); i++) {
                for (int j = 0; j < selectdwysall.size(); j++) {
                    if (selectdwwtzsall.get(i).get("department_name").toString().equals(selectdwysall.get(j).get("department_name").toString())) {
                        String zsl = selectdwwtzsall.get(i).get("sl").toString();
                        String yys = selectdwysall.get(j).get("sl").toString();
                        int zsl1 = Integer.parseInt(zsl);
                        int yys1 = Integer.parseInt(yys);
                        Map dataMap = new HashMap();
                        dataMap.put("department_name", selectdwwtzsall.get(i).get("department_name").toString());
                        if (zsl1 > 0) {
                            String num = df.format((double) yys1 / zsl1 * 100);//返回的是String类型
                            dataMap.put("wcl", num);
                        } else {
                            dataMap.put("wcl", "0.00");
                        }
                        result2.add(dataMap);
                    }
                }
            }
            map.put("wtdwwcl", result2);
            /*年减量=去年问题数-今年问题数   减量比=（去年问题数-今年问题数）/今年问题数    */
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date creatdate = sdf.parse(creattime);    //传入的开始时间
            calendar.setTime(creatdate);
            calendar.add(Calendar.YEAR, -1);//减少一年
            creattime = sdf.format(calendar.getTime());

            Date enddate = sdf.parse(endtime);    //传入的结束时间
            calendar.setTime(enddate);
            calendar.add(Calendar.YEAR, -1);//减少一年
            endtime = sdf.format(calendar.getTime());
            int cutnum = wordExService.selectall(creattime, endtime); //对比选择日期，前一年的问题总数
            int cut = a - cutnum;
            map.put("jswtsl", cut);
            retVo = ResultVoUtil.success("查询成功", map, "400");

        } catch (Exception e) {
            e.printStackTrace();
            return ResultVoUtil.error("9999", "查询失败，未知错误", e);
        }

        return retVo;
    }

    @RequestMapping(value = "/exword", method = RequestMethod.POST)
    public void exword(@RequestBody JSONObject jSONArray, HttpServletResponse response) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        WordExUtil w = new WordExUtil();
        List<String> list1 = new ArrayList<String>();
        JSONArray ja = jSONArray.getJSONArray("wtfxfslb");//获取问题发现方式列表
        JSONArray ja1 = jSONArray.getJSONArray("wtdwfblb");//获取问题单位分布列表
        JSONArray ja2 = jSONArray.getJSONArray("wtzylb");//获取问题专业类别列表
        JSONArray ja3 = jSONArray.getJSONArray("wtywsxlb");//获取问题单位分布列表
        JSONArray ja4 = jSONArray.getJSONArray("wtsscmlb");//获取问题所属层面列表
        JSONArray ja5 = jSONArray.getJSONArray("wtglhjlb");//获取问题管理环节列表
        JSONArray ja6 = jSONArray.getJSONArray("wtlblb");//获取问题类别列表
        JSONArray ja7 = jSONArray.getJSONArray("wtdytxdylb");//获取问题对应体系单元列表
        JSONArray ja8 = jSONArray.getJSONArray("wtdytxyslb");//获取问题单位分布列表
        JSONArray ja9 = jSONArray.getJSONArray("wtyzcdlb");//获取问题严重程度列表
        JSONArray ja10 = jSONArray.getJSONArray("sfslwt1");//获取问题三老总列表
        JSONArray ja11 = jSONArray.getJSONArray("sfslwt2");//获取问题三老单位列表
        JSONArray ja12 = jSONArray.getJSONArray("sfzdbl1");//获取主动暴露问题总分布列表
        JSONArray ja13 = jSONArray.getJSONArray("sfzdbl2");//获取主动暴露问题单位分布列表
        JSONArray ja14 = jSONArray.getJSONArray("wtzgz");//获取问题总列表
        List ja16 = jSONArray.getJSONArray("base");//获取问题发现方式列表
        String zwcl = jSONArray.getString("zwcl");
        String jswtsl = jSONArray.getString("jswtsl");
        String wtzs = jSONArray.getString("wtzs");
        String creattime = jSONArray.getString("creattime");
        String endtime = jSONArray.getString("endtime");
        dataMap.put("wtzs", wtzs);

        /*  String cutnum = jSONArray.getString("cutnum");
         */
        JSONArray ja15 = jSONArray.getJSONArray("wtzgdw");//获取问题单位分布列表
        int cnum = Integer.parseInt(jswtsl);
        String cut = "";
        if (cnum > 0) {
            cut = "增加" + cnum + "项";

        } else {
            int b = Math.abs(cnum);
            cut = "减少" + b + "项";

        }
        dataMap.put("jswtsl", cut);   //增加/减少

        String wtfxfsqk = "";//问题发现方式情况
        for (int i = 0; i < ja.size(); i++) {
            JSONObject c = ja.getJSONObject(i);
            String n;
            if (i == ja.size() - 1) {
                n = c.get("wtfxfs").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("wtfxfs").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtfxfsqk = wtfxfsqk + n;
        }
        dataMap.put("wtfxfsqk", wtfxfsqk);

        String wtdwfbqk = "";//问题单位分布情况
        for (int i = 0; i < ja1.size(); i++) {
            JSONObject c = ja1.getJSONObject(i);
            String n;
            if (i == ja1.size() - 1) {
                n = c.get("department_name").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("department_name").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdwfbqk = wtdwfbqk + n;
        }
        dataMap.put("wtdwfbqk", wtdwfbqk);

        String wtzyleqk = "";//问题专业类别情况
        for (int i = 0; i < ja2.size(); i++) {
            JSONObject c = ja2.getJSONObject(i);
            String n;
            if (i == ja2.size() - 1) {
                n = c.get("zylb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("zylb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtzyleqk = wtzyleqk + n;
        }
        dataMap.put("wtzyleqk", wtzyleqk);

        String wtywsxqk = "";//问题所属层面情况
        for (int i = 0; i < ja3.size(); i++) {
            JSONObject c = ja3.getJSONObject(i);
            String n;
            if (i == ja3.size() - 1) {
                n = c.get("ywsx").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("ywsx").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtywsxqk = wtywsxqk + n;
        }
        dataMap.put("wtywsxqk", wtywsxqk);

        String wtsscmqk = "";//问题所属层面情况
        for (int i = 0; i < ja4.size(); i++) {
            JSONObject c = ja4.getJSONObject(i);
            String n;
            if (i == ja4.size() - 1) {
                n = c.get("sscm").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("sscm").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtsscmqk = wtsscmqk + n;
        }
        dataMap.put("wtsscmqk", wtsscmqk);

        String wtglhjqk = "";//问题管理环节情况
        for (int i = 0; i < ja5.size(); i++) {
            JSONObject c = ja5.getJSONObject(i);
            String n;
            if (i == ja5.size() - 1) {
                n = c.get("glhj").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("glhj").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtglhjqk = wtglhjqk + n;
        }
        dataMap.put("wtglhjqk", wtglhjqk);

        String wtlbfbqk = "";//问题类别分布情况
        for (int i = 0; i < ja6.size(); i++) {
            JSONObject c = ja6.getJSONObject(i);
            String n;
            if (i == ja6.size() - 1) {
                n = c.get("lb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("lb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtlbfbqk = wtlbfbqk + n;
        }
        dataMap.put("wtlbfbqk", wtlbfbqk);

        String wtdytxdyqk = "";//问题对应体系单元情况
        for (int i = 0; i < ja7.size(); i++) {
            JSONObject c = ja7.getJSONObject(i);
            String n;
            if (i == ja7.size() - 1) {
                n = c.get("dytxdy").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("dytxdy").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdytxdyqk = wtdytxdyqk + n;
        }
        dataMap.put("wtdytxdyqk", wtdytxdyqk);

        String wtdyysqk = "";//问题对应体系元素情况
        for (int i = 0; i < ja8.size(); i++) {
            JSONObject c = ja8.getJSONObject(i);
            String n;
            if (i == ja8.size() - 1) {
                n = c.get("dytxys").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("dytxys").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdyysqk = wtdyysqk + n;
        }
        dataMap.put("wtdyysqk", wtdyysqk);

        String wtyzcdqk = "";//问题严重程度情况
        for (int i = 0; i < ja9.size(); i++) {
            JSONObject c = ja9.getJSONObject(i);
            String n;
            if (i == ja9.size() - 1) {
                n = c.get("wtyzcd").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("wtyzcd").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtyzcdqk = wtyzcdqk + n;
        }
        dataMap.put("wtyzcdqk", wtyzcdqk);

        String sfslwtqk = "";//是否三老问题情况
        for (int i = 0; i < ja10.size(); i++) {
            JSONObject c = ja10.getJSONObject(i);
            String n;
            if (i == ja10.size() - 1) {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项三老问题" + "。";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是三老问题" + "。";
                }

            } else {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项三老问题" + "，";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是三老问题" + "，";
                }

            }
            sfslwtqk = sfslwtqk + n;

        }
        dataMap.put("sfslwtqk", sfslwtqk);

        List slwtdwqkList = new ArrayList();
        //是否三老问题单位情况
        for (int i = 0; i < ja11.size(); i++) {
            JSONObject c = ja11.getJSONObject(i);
            int j = i + 1;
            String n;
            n = "(" + j + ")" + c.getString("department_name") + "共发现" + c.getString("sl") + "项三老问题。";
            Map map = new HashMap();
            map.put("slwtdwqk", n);
            slwtdwqkList.add(map);
        }
        dataMap.put("slwtdwqkList", slwtdwqkList);

        String wtzdblqk = "";//是否主动暴露问题情况
        for (int i = 0; i < ja12.size(); i++) {
            JSONObject c = ja12.getJSONObject(i);
            String n;
            if (i == ja12.size() - 1) {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项主动暴露问题" + "。";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是主动暴露问题" + "。";
                }

            } else {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项主动暴露问题" + "，";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是主动暴露问题" + "，";
                }

            }
            wtzdblqk = wtzdblqk + n;
        }
        dataMap.put("wtzdblqk", wtzdblqk);

        //是否主动暴露问题单位情况
        List zdbldwqkList = new ArrayList();
        for (int i = 0; i < ja13.size(); i++) {
            JSONObject c = ja13.getJSONObject(i);
            int j = i + 1;
            String n;
            n = "(" + j + ")" + c.getString("department_name") + "共发现" + c.getString("sl") + "项主动暴露问题。";
            Map map = new HashMap();
            map.put("zdbldwqk", n);
            zdbldwqkList.add(map);
        }
        dataMap.put("zdbldwqkList", zdbldwqkList);

        String wtzgzqk = "";//问题整改总情况情况
        String d = "";
        for (int i = 0; i < ja14.size(); i++) {
            JSONObject c = ja14.getJSONObject(i);
            String n;

            wtzgzqk = "各单位总整改率为" + zwcl + "%,其中";
            if (i == ja14.size() - 1) {
                n = c.getString("lb") + "有" + c.getString("sl") + "项。";
            } else {
                n = c.getString("lb") + "有" + c.getString("sl") + "项，";
            }
            d = d + n;
        }
        wtzgzqk = wtzgzqk + d;
        dataMap.put("wtzgzqk", wtzgzqk);

        //问题整改单位情况
        List wtzgdwqkList = new ArrayList();
        String n;
        for (int i = 0; i < ja15.size(); i++) {
            JSONObject c = ja15.getJSONObject(i);
            int j = i + 1;
            n = "(" + j + ")" + c.getString("mc") + "整改率为" + c.getString("wcl") + "%，其中未启动" + c.getString("noqid") + "项，" +
                    "待整改" + c.getString("daizhenggai") + "项，" + "待审核" + c.getString("daishenhe") + "项，" + "待落实" + c.getString("dailuoshi") + "项，"
                    + "待验收" + c.getString("daiyanshou") + "项，" + "已验收" + c.getString("yiyans") + "项。";
            Map map = new HashMap();
            map.put("wtzgdwqk", n);
            wtzgdwqkList.add(map);
        }
        dataMap.put("wtzgdwqkList", wtzgdwqkList);

        for (int i = 0; i < ja16.size(); i++) {
            String base64Data = ja16.get(i).toString().substring(ja16.get(i).toString().indexOf(",") + 1);
            dataMap.put("img" + i, base64Data);//问题发现方式图表
        }
        dataMap.put("strattime", creattime);//开始时间
        dataMap.put("endtime", endtime);//结束时间
        w.createDoc(dataMap, response);
    }

    @RequestMapping(value = "/selectdw")
    public ResultVo selectdw(@RequestParam("creattime") String creattime, @RequestParam("endtime") String endtime, @RequestParam("dwmc") String dwmc) {
        ResultVo retVo = null;
        try {
            Calendar calendar = Calendar.getInstance();
            if ("".equals(creattime) || "".equals(endtime)) {
                int year = calendar.get(Calendar.YEAR);
                String years = String.valueOf(year);
                creattime = years + "-01-01";
                endtime = years + "-12-31";
            }
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("creattime", creattime);
            map.put("endtime", endtime);
            map.put("dwmc", dwmc);
            List<Map> list1 = wordExService.selectdw1(creattime, endtime, dwmc);//查询问题发现方式分类汇总
            List<Map> list2 = wordExService.selectdw2(creattime, endtime, dwmc);//查询问题部门分布情况
            List<Map> list3 = wordExService.selectdw3(creattime, endtime, dwmc);//查询问题专业类别分布情况
            List<Map> list4 = wordExService.selectdw4(creattime, endtime, dwmc);//查询问题业务事项分布情况
            List<Map> list5 = wordExService.selectdw5(creattime, endtime, dwmc);//查询问题所属层面分布情况
            List<Map> list6 = wordExService.selectdw6(creattime, endtime, dwmc);//查询问题管理环节分布情况
            List<Map> list7 = wordExService.selectdw7(creattime, endtime, dwmc);//查询问题类别分布情况
            List<Map> list8 = wordExService.selectdw8(creattime, endtime, dwmc);//查询问题对应体系单元分布情况
            List<Map> list9 = wordExService.selectdw9(creattime, endtime, dwmc);//查询问题对应体系要素分布情况
            List<Map> list10 = wordExService.selectdw10(creattime, endtime, dwmc);//查询问题严重程度分布情况
            List<Map> list11 = wordExService.selectdwsl1(creattime, endtime, dwmc);//查询三老问题分布情况
            List<Map> list12 = wordExService.selectdwsl2(creattime, endtime, dwmc);//查询三老问题单位分布情况
            List<Map> list13 = wordExService.selectdwbl1(creattime, endtime, dwmc);//查询是否主动暴露分布情况
            List<Map> list14 = wordExService.selectdwbl2(creattime, endtime, dwmc);//查询是否主动暴露单位分布情况
            List<Map> list15 = wordExService.selectdwzq1(creattime, endtime, dwmc);//查询问题整改情况
            List<Map> list16 = wordExService.selectdwzq2(creattime, endtime, dwmc);//查询问题整改情况
            int a = wordExService.selectdwwenti(creattime, endtime, dwmc);//查询问题总数
            int dwys = wordExService.selectdwys(creattime, endtime, dwmc);
            DecimalFormat df = new DecimalFormat("0.00");//格式化小数
            String d = "";
            map.put("wtzs", a);
            if (a > 0) {
                String zwcl = df.format((double) dwys / a * 100);
                map.put("zwcl", zwcl);
            } else {
                map.put("zwcl", "0.00");
            }

            /* 问题发现方式开始+++++++++++++++++++++++++++++++++++++++++*/
            //问题发现方式占比
            if (list1.size() > 0) {
                for (int i = 0; i < list1.size(); i++) {
                    d = list1.get(i).get("sl").toString(); //获取每一项的数量
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list1.get(i).put("num", num);
                }
            }
            // 2021-6-28 ybq改：添加自定义
            Map<String, Object> othen = new HashMap<>();
            othen.put("wtfxfs", "其他");
            int wtfxfs_sl = 0;
            double wtfxfs_num = 0;
            List<Map> wtfxfslb = new ArrayList<>();
            for (Map data : list1) {
                if (config.getFoundWay().contains(data.get("wtfxfs"))) {
                    wtfxfslb.add(data);
                } else {
                    wtfxfs_sl += Integer.parseInt(data.get("sl").toString());
                    wtfxfs_num += Double.parseDouble(data.get("num").toString());
                }
            }
            if (wtfxfs_sl > 0) {
                othen.put("sl", wtfxfs_sl);
                othen.put("num", wtfxfs_num + "");
                wtfxfslb.add(othen);
                wtfxfslb.sort((u1, u2) -> {
                    int diff = Integer.parseInt(u1.get("sl").toString()) - Integer.parseInt(u2.get("sl").toString());
                    if (diff > 0) {
                        return 1;
                    } else if (diff < 0) {
                        return -1;
                    }
                    return 0; //相等为0
                });
            }
            map.put("wtfxfslb", wtfxfslb); //将问题发现方式列表存放
            /* 问题发现方式结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list2.size() > 0) {
                for (int i = 0; i < list2.size(); i++) {
                    d = list2.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list2.get(i).put("num", num);
                }
            }
            map.put("wtdwfblb", list2);
            /* 问题单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题专业类别开始+++++++++++++++++++++++++++++++++++++++++*/
            //问题发现方式占比
            List<String> wtzylb = new ArrayList<>();
            List<String> typeList = config.getProfessionalType();
            if (list3.size() > 0) {
                for (int i = 0; i < list3.size(); i++) {
                    d = list3.get(i).get("sl").toString(); //获取每一项的数量
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list3.get(i).put("num", num);
                    if (typeList.contains(list3.get(i).get("zylb"))) {
                        wtzylb.add(list3.get(i).get("zylb").toString());
                    }
                }
            }
            for (String type : typeList) {
                if (!wtzylb.contains(type)) {
                    Map data = new HashMap();
                    data.put("zylb", type);
                    data.put("sl", 0);
                    data.put("num", "0");
                    list3.add(data);
                }
            }
            map.put("wtzylb", list3);
            /* 问题专业类别结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题业务事项分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list4.size() > 0) {
                for (int i = 0; i < list4.size(); i++) {
                    d = list4.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list4.get(i).put("num", num);
                }
            }
            map.put("wtywsxlb", list4);
            /* 问题业务事项分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题所属层面分布开始+++++++++++++++++++++++++++++++++++++++++*/
            List<String> levelList = config.getLevel();
            if (list5.size() > 0) {
                for (int i = 0; i < list5.size(); i++) {
                    d = list5.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list5.get(i).put("num", num);
                }
            }
            List<Map> wtsscmlb = new ArrayList<>();
            for (String level : levelList) {
                boolean wtsscmlbCon = true;
                for (Map value : list5) {
                    if (value.get("sscm").equals(level)) {
                        wtsscmlb.add(value);
                        wtsscmlbCon = false;
                        break;
                    }
                }
                if (wtsscmlbCon) {
                    Map data = new HashMap();
                    data.put("sscm", level);
                    data.put("sl", 0);
                    data.put("num", "0");
                    wtsscmlb.add(data);
                }
            }
            map.put("wtsscmlb", wtsscmlb);
            /* 问题所属层面分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题管理环节分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list6.size() > 0) {
                for (int i = 0; i < list6.size(); i++) {
                    d = list6.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list6.get(i).put("num", num);
                }
            }
            map.put("wtglhjlb", list6);
            /* 问题管理环节分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题类别分布开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list7.size() > 0) {
                for (int i = 0; i < list7.size(); i++) {
                    d = list7.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list7.get(i).put("num", num);
                }
            }
            map.put("wtlblb", list7);
            /* 问题类别分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题对应体系单元开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list8.size() > 0) {
                for (int i = 0; i < list8.size(); i++) {
                    d = list8.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list8.get(i).put("num", num);
                }
            }
            map.put("wtdytxdylb", list8);
            /* 问题对应体系单元结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题对应体系要素开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list9.size() > 0) {
                for (int i = 0; i < list9.size(); i++) {
                    d = list9.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list9.get(i).put("num", num);
                }
            }
            map.put("wtdytxyslb", list9);
            /* 问题对应体系要素结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 问题严重程度开始+++++++++++++++++++++++++++++++++++++++++*/
            List<String> severityList = config.getSeverity();
            if (list10.size() > 0) {
                for (int i = 0; i < list10.size(); i++) {
                    d = list10.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    String num = df.format((double) e / a * 100);//返回的是String类型
                    list10.get(i).put("num", num);
                }
            }
            List<Map> wtyzcdlb = new ArrayList<>();
            for (String severity : severityList) {
                boolean wtyzcdlbCon = true;
                for (Map value : list10) {
                    if (value.get("wtyzcd").equals(severity)) {
                        wtyzcdlb.add(value);
                        wtyzcdlbCon = false;
                        break;
                    }
                }
                if (wtyzcdlbCon) {
                    Map data = new HashMap();
                    data.put("wtyzcd", severity);
                    data.put("sl", 0);
                    data.put("num", "0");
                    wtyzcdlb.add(data);
                }
            }
            map.put("wtyzcdlb", wtyzcdlb);
            /* 问题严重成结束+++++++++++++++++++++++++++++++++++++++++*/
            /* 是否三老问题总开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfslwt1", list11);
            /* 是否三老问题总结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否三老问题单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfslwt2", list12);
            /* 是否三老问题单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否主动暴露总开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfzdbl1", list13);
            /* 是否主动暴露总结束+++++++++++++++++++++++++++++++++++++++++*/

            /* 是否主动暴露单位分布开始+++++++++++++++++++++++++++++++++++++++++*/
            map.put("sfzdbl2", list14);
            /* 是否主动暴露单位分布结束+++++++++++++++++++++++++++++++++++++++++*/

            /*问题整改总开始+++++++++++++++++++++++++++++++++++++++++*/
            if (list15.size() > 0) {
                for (int i = 0; i < list15.size(); i++) {
                    d = list15.get(i).get("sl").toString();
                    int e = Integer.parseInt(d);
                    if (a > 0) {
                        String num = df.format((double) e / a * 100);//返回的是String类型
                        list15.get(i).put("num", num);
                    } else {
                        list15.get(i).put("num", "0.00");
                    }

                }
            }
            map.put("wtzgz", list15);
            /* 问题整改总结束+++++++++++++++++++++++++++++++++++++++++*/

            /*问题整改总开始+++++++++++++++++++++++++++++++++++++++++*/
            List<Map> bmmcList = wordExService.selectBmmc(dwmc);
            List result = new ArrayList();
            for (Map depart : bmmcList) {
                List datas = findAlllInData(depart, list16); //在datalist里面找与depart相同的记录，返回一个数组
                Map dataMap = new HashMap();
                dataMap.put(depart.get("department_name"), datas);
                result.add(dataMap);
            }

            map.put("wtzgdw", result);
            /*问题整改总开始+++++++++++++++++++++++++++++++++++++++++*/

            List result2 = new ArrayList();
            List<Map> selectbmwtzsall = wordExService.selectbmwtzsall(creattime, endtime, dwmc);  //各单位问题总数
            List<Map> selectbmysall = wordExService.selectbmysall(creattime, endtime, dwmc);//各单位已验收问题总数
            for (int i = 0; i < selectbmwtzsall.size(); i++) {
                for (int j = 0; j < selectbmysall.size(); j++) {
                    if (selectbmwtzsall.get(i).get("department_name").toString().equals(selectbmysall.get(j).get("department_name").toString())) {
                        String zsl = selectbmwtzsall.get(i).get("sl").toString();
                        String yys = selectbmysall.get(j).get("sl").toString();
                        int zsl1 = Integer.parseInt(zsl);
                        int yys1 = Integer.parseInt(yys);
                        Map dataMap = new HashMap();
                        dataMap.put("department_name", selectbmwtzsall.get(i).get("department_name").toString());
                        if (zsl1 > 0) {
                            String num = df.format((double) yys1 / zsl1 * 100);//返回的是String类型
                            dataMap.put("wcl", num);
                        } else {
                            dataMap.put("wcl", "0.00");
                        }
                        result2.add(dataMap);
                    }
                }
            }
            map.put("wtdwwcl", result2);

            /*年减量=去年问题数-今年问题数   减量比=（去年问题数-今年问题数）/今年问题数    */
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date creatdate = sdf.parse(creattime);    //传入的开始时间
            calendar.setTime(creatdate);
            calendar.add(Calendar.YEAR, -1);//减少一年
            creattime = sdf.format(calendar.getTime());

            Date enddate = sdf.parse(endtime);    //传入的结束时间
            calendar.setTime(enddate);
            calendar.add(Calendar.YEAR, -1);//减少一年
            endtime = sdf.format(calendar.getTime());
            int cutnum = wordExService.selectdwwenti(creattime, endtime, dwmc); //对比选择日期，前一年的问题总数
            int cut = a - cutnum;
            map.put("jswtsl", cut);
            retVo = ResultVoUtil.success("查询成功", map, "400");

        } catch (Exception e) {
            e.printStackTrace();
            return retVo = ResultVoUtil.error("9999", "查询失败，未知错误", e);
        }
        return retVo;
    }

    @RequestMapping(value = "/exworddw", method = RequestMethod.POST)
    public void exworddw(@RequestBody JSONObject jSONArray, HttpServletResponse response) throws Exception {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        WordExUtil w = new WordExUtil();
        List<String> list1 = new ArrayList<String>();
        JSONArray ja = jSONArray.getJSONArray("wtfxfslb");//获取问题发现方式列表
        JSONArray ja1 = jSONArray.getJSONArray("wtdwfblb");//获取问题单位分布列表
        JSONArray ja2 = jSONArray.getJSONArray("wtzylb");//获取问题专业类别列表
        JSONArray ja3 = jSONArray.getJSONArray("wtywsxlb");//获取问题单位分布列表
        JSONArray ja4 = jSONArray.getJSONArray("wtsscmlb");//获取问题所属层面列表
        JSONArray ja5 = jSONArray.getJSONArray("wtglhjlb");//获取问题管理环节列表
        JSONArray ja6 = jSONArray.getJSONArray("wtlblb");//获取问题类别列表
        JSONArray ja7 = jSONArray.getJSONArray("wtdytxdylb");//获取问题对应体系单元列表
        JSONArray ja8 = jSONArray.getJSONArray("wtdytxyslb");//获取问题单位分布列表
        JSONArray ja9 = jSONArray.getJSONArray("wtyzcdlb");//获取问题严重程度列表
        JSONArray ja10 = jSONArray.getJSONArray("sfslwt1");//获取问题三老总列表
        JSONArray ja11 = jSONArray.getJSONArray("sfslwt2");//获取问题三老单位列表
        JSONArray ja12 = jSONArray.getJSONArray("sfzdbl1");//获取主动暴露问题总分布列表
        JSONArray ja13 = jSONArray.getJSONArray("sfzdbl2");//获取主动暴露问题单位分布列表
        JSONArray ja14 = jSONArray.getJSONArray("wtzgz");//获取问题总列表
        List ja16 = jSONArray.getJSONArray("base");//获取问题发现方式列表
        String zwcl = jSONArray.getString("zwcl");
        String jswtsl = jSONArray.getString("jswtsl");
        String wtzs = jSONArray.getString("wtzs");
        String creattime = jSONArray.getString("creattime");
        String endtime = jSONArray.getString("endtime");
        String dwmc = jSONArray.getString("dwmc");
        dataMap.put("wtzs", wtzs);

        /*  String cutnum = jSONArray.getString("cutnum");
         */
        JSONArray ja15 = jSONArray.getJSONArray("wtzgdw");//获取问题单位分布列表
        int cnum = Integer.parseInt(jswtsl);
        String cut = "";
        if (cnum > 0) {
            cut = "增加" + cnum + "项";

        } else {
            int b = Math.abs(cnum);
            cut = "减少" + b + "项";

        }
        dataMap.put("jswtsl", cut);   //增加/减少

        String wtfxfsqk = "";//问题发现方式情况
        for (int i = 0; i < ja.size(); i++) {
            JSONObject c = ja.getJSONObject(i);
            String n;
            if (i == ja.size() - 1) {
                n = c.get("wtfxfs").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("wtfxfs").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtfxfsqk = wtfxfsqk + n;
        }
        dataMap.put("wtfxfsqk", wtfxfsqk);

        String wtdwfbqk = "";//问题单位分布情况
        for (int i = 0; i < ja1.size(); i++) {
            JSONObject c = ja1.getJSONObject(i);
            String n;
            if (i == ja1.size() - 1) {
                n = c.get("department_name").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("department_name").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdwfbqk = wtdwfbqk + n;
        }
        dataMap.put("wtdwfbqk", wtdwfbqk);

        String wtzyleqk = "";//问题专业类别情况
        for (int i = 0; i < ja2.size(); i++) {
            JSONObject c = ja2.getJSONObject(i);
            String n;
            if (i == ja2.size() - 1) {
                n = c.get("zylb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("zylb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtzyleqk = wtzyleqk + n;
        }
        dataMap.put("wtzyleqk", wtzyleqk);

        String wtywsxqk = "";//问题所属层面情况
        for (int i = 0; i < ja3.size(); i++) {
            JSONObject c = ja3.getJSONObject(i);
            String n;
            if (i == ja3.size() - 1) {
                n = c.get("ywsx").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("ywsx").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtywsxqk = wtywsxqk + n;
        }
        dataMap.put("wtywsxqk", wtywsxqk);

        String wtsscmqk = "";//问题所属层面情况
        for (int i = 0; i < ja4.size(); i++) {
            JSONObject c = ja4.getJSONObject(i);
            String n;
            if (i == ja4.size() - 1) {
                n = c.get("sscm").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("sscm").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtsscmqk = wtsscmqk + n;
        }
        dataMap.put("wtsscmqk", wtsscmqk);

        String wtglhjqk = "";//问题管理环节情况
        for (int i = 0; i < ja5.size(); i++) {
            JSONObject c = ja5.getJSONObject(i);
            String n;
            if (i == ja5.size() - 1) {
                n = c.get("glhj").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("glhj").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtglhjqk = wtglhjqk + n;
        }
        dataMap.put("wtglhjqk", wtglhjqk);

        String wtlbfbqk = "";//问题类别分布情况
        for (int i = 0; i < ja6.size(); i++) {
            JSONObject c = ja6.getJSONObject(i);
            String n;
            if (i == ja6.size() - 1) {
                n = c.get("lb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("lb").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtlbfbqk = wtlbfbqk + n;
        }
        dataMap.put("wtlbfbqk", wtlbfbqk);

        String wtdytxdyqk = "";//问题对应体系单元情况
        for (int i = 0; i < ja7.size(); i++) {
            JSONObject c = ja7.getJSONObject(i);
            String n;
            if (i == ja7.size() - 1) {
                n = c.get("dytxdy").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("dytxdy").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdytxdyqk = wtdytxdyqk + n;
        }
        dataMap.put("wtdytxdyqk", wtdytxdyqk);

        String wtdyysqk = "";//问题对应体系元素情况
        for (int i = 0; i < ja8.size(); i++) {
            JSONObject c = ja8.getJSONObject(i);
            String n;
            if (i == ja8.size() - 1) {
                n = c.get("dytxys").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("dytxys").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtdyysqk = wtdyysqk + n;
        }
        dataMap.put("wtdyysqk", wtdyysqk);

        String wtyzcdqk = "";//问题严重程度情况
        for (int i = 0; i < ja9.size(); i++) {
            JSONObject c = ja9.getJSONObject(i);
            String n;
            if (i == ja9.size() - 1) {
                n = c.get("wtyzcd").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%。";
            } else {
                n = c.get("wtyzcd").toString() + "发现" + c.get("sl").toString() + "项问题、占比" + c.get("num").toString() + "%,";
            }
            wtyzcdqk = wtyzcdqk + n;
        }
        dataMap.put("wtyzcdqk", wtyzcdqk);

        String sfslwtqk = "";//是否三老问题情况
        for (int i = 0; i < ja10.size(); i++) {
            JSONObject c = ja10.getJSONObject(i);
            String n;
            if (i == ja10.size() - 1) {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项三老问题" + "。";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是三老问题" + "。";
                }

            } else {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项三老问题" + "，";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是三老问题" + "，";
                }

            }
            sfslwtqk = sfslwtqk + n;
        }
        dataMap.put("sfslwtqk", sfslwtqk);

        List slwtdwqkList = new ArrayList();
        //是否三老问题单位情况
        for (int i = 0; i < ja11.size(); i++) {
            JSONObject c = ja11.getJSONObject(i);
            int j = i + 1;
            String n;
            n = "(" + j + ")" + c.getString("department_name") + "共发现" + c.getString("sl") + "项三老问题。";
            Map map = new HashMap();
            map.put("slwtdwqk", n);
            slwtdwqkList.add(map);
        }
        dataMap.put("slwtdwqkList", slwtdwqkList);

        String wtzdblqk = "";//是否主动暴露问题情况
        for (int i = 0; i < ja12.size(); i++) {
            JSONObject c = ja12.getJSONObject(i);
            String n;
            if (i == ja12.size() - 1) {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项主动暴露问题" + "。";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是主动暴露问题" + "。";
                }

            } else {
                if ("是".equals(c.getString("name"))) {
                    n = "共发现" + c.get("sl").toString() + "项主动暴露问题" + "，";
                } else {
                    n = "发现" + c.get("sl").toString() + "项不是主动暴露问题" + "，";
                }

            }
            wtzdblqk = wtzdblqk + n;
        }
        dataMap.put("wtzdblqk", wtzdblqk);

        //是否主动暴露问题单位情况
        List zdbldwqkList = new ArrayList();
        for (int i = 0; i < ja13.size(); i++) {
            JSONObject c = ja13.getJSONObject(i);
            int j = i + 1;
            String n;
            n = "(" + j + ")" + c.getString("department_name") + "共发现" + c.getString("sl") + "项主动暴露问题。";
            Map map = new HashMap();
            map.put("zdbldwqk", n);
            zdbldwqkList.add(map);
        }
        dataMap.put("zdbldwqkList", zdbldwqkList);
        String wtzgzqk = "";//问题整改总情况情况
        String d = "";
        for (int i = 0; i < ja14.size(); i++) {
            JSONObject c = ja14.getJSONObject(i);
            String n;

            wtzgzqk = "各单位总整改率为" + zwcl + "%,其中";
            if (i == ja14.size() - 1) {
                n = c.getString("lb") + "有" + c.getString("sl") + "项。";
            } else {
                n = c.getString("lb") + "有" + c.getString("sl") + "项，";
            }
            d = d + n;
        }
        wtzgzqk = wtzgzqk + d;
        dataMap.put("wtzgzqk", wtzgzqk);
        //问题整改单位情况
//        JSONArray departname = jSONArray.getJSONArray("test");//获取主动暴露问题单位分布列表
        String n;
        List wtzgdwqkList = new ArrayList();
        for (int i = 0; i < ja15.size(); i++) {
            JSONObject c = ja15.getJSONObject(i);
            int j = i + 1;

            n = "(" + j + ")" + c.getString("mc") + "整改率为" + c.getString("wcl") + "%，其中未启动" + c.getString("noqid") + "项，" +
                    "待整改" + c.getString("daizhenggai") + "项，" + "待审核" + c.getString("daishenhe") + "项，" + "待落实" + c.getString("dailuoshi") + "项，"
                    + "待验收" + c.getString("daiyanshou") + "项，" + "已验收" + c.getString("yiyans") + "项。";
            Map map = new HashMap();
            map.put("wtzgdwqk", n);
            wtzgdwqkList.add(map);
        }
        dataMap.put("wtzgdwqkList", wtzgdwqkList);
        for (int i = 0; i < ja16.size(); i++) {
            String base64Data = ja16.get(i).toString().substring(ja16.get(i).toString().indexOf(",") + 1);
            dataMap.put("img" + i, base64Data);//问题发现方式图表
        }
        dataMap.put("dwmc", dwmc);//开始时间
        dataMap.put("strattime", creattime);//开始时间
        dataMap.put("endtime", endtime);//结束时间
        w.createdwDoc(dataMap, response);
    }

    @GetMapping(value = "/xiazaimoban")
    public void xiazaimoban(HttpServletResponse response, String code, HttpServletRequest request) {
        try {
            // path是指欲下载的文件的路径。
            File file1 = new File("");
            String abspath = file1.getCanonicalPath();
            String path = "";
            if ("1".equals(code)) {
                path = abspath + "/src/main/resources/templates/单位自查发现问题表模板.xlsx";
            } else {
                path = abspath + "/src/main/resources/templates/公司检查发现问题表模板.xlsx";
            }

            File file = new File(path);
            // 取得文件名。
            String formFileName = file.getName();
            // 取得文件的后缀名。
//            String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase();
            String userAgent = request.getHeader("User-Agent");
            // 针对IE或者以IE为内核的浏览器：
            if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
                formFileName = java.net.URLEncoder.encode(formFileName, "UTF-8");
            } else {
                // 非IE浏览器的处理：
                formFileName = new String(formFileName.getBytes("UTF-8"), "ISO-8859-1");
            }

            // 以流的形式下载文件。
            InputStream fis = new BufferedInputStream(new FileInputStream(path));
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            // 清空response
            response.reset();
            // 设置response的Header
            response.addHeader("Content-Disposition", "attachment;filename=" + new String(formFileName.getBytes()));
            response.addHeader("Content-Length", "" + file.length());
            OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
            response.setContentType("application/octet-stream");
            response.setCharacterEncoding("UTF-8");
            toClient.write(buffer);
            toClient.flush();
            toClient.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }

    /**
     * 查询单位的数据
     *
     * @param depart
     * @param datalist
     * @return
     */
    public List findAlllInData(Map depart, List<Map> datalist) {
        List result = new ArrayList();
        for (Map data : datalist) {
            if (depart.get("department_name").equals(data.get("department_name").toString())) {
                result.add(data);
            }

        }
        return result;
    }

    public List findAlllInData1(Map depart, List<Map> datalist) {
        List result = new ArrayList();
        for (Map data : datalist) {
            if (depart.get("department_name").equals(data.get("department_name").toString())) {
                result.add(data);
            }

        }
        return result;
    }

}
